package cn.edu.flow.test;

import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

/**
 * 测试流程任务
 */
@Slf4j
@SpringBootTest
public class Part4_Task {

    @Autowired
    private TaskService taskService;

    /**
     * 任务查询
     */
    @Test
    public void getTasks(){
        List<Task> list = taskService.createTaskQuery().list();
        for(Task tk : list){
            log.info("Id："+tk.getId());
            log.info("Name："+tk.getName());
            log.info("Assignee："+tk.getAssignee());
        }
    }

    /**
     * 查询我的代办任务
     */
    @Test
    public void getTasksByAssignee(){
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee("bajie")
                .list();
        for(Task tk : list){
            log.info("Id："+tk.getId());
            log.info("Name："+tk.getName());
            log.info("Assignee："+tk.getAssignee());
        }

    }


    /**
     * 执行任务
     */
    @Test
    public void completeTask(){
        taskService.complete("83229708-6513-11ee-aca2-9829a6889d5e");
        log.info("完成任务");

    }

    /**
     * 拾取任务
     */
    @Test
    public void claimTask(){
        Task task = taskService.createTaskQuery().taskId("1f2a8edf-cefa-11ea-84aa-dcfb4875e032").singleResult();
        taskService.claim("1f2a8edf-cefa-11ea-84aa-dcfb4875e032","bajie");
    }

    /**
     * 归还与交办任务
     */
    @Test
    public void setTaskAssignee(){
        Task task = taskService.createTaskQuery().taskId("1f2a8edf-cefa-11ea-84aa-dcfb4875e032").singleResult();
        taskService.setAssignee("1f2a8edf-cefa-11ea-84aa-dcfb4875e032",null);//归还候选任务
        taskService.setAssignee("1f2a8edf-cefa-11ea-84aa-dcfb4875e032","wukong");//交办
    }

}
